<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>选择级别</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <style media="screen">
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
        }

        #app{
          display: flex;
          flex-direction: column;
            height: 100%;
            background-color: #FEE407;
        }

        #header{
          margin-bottom: -5rem;
          flex: 4;
        }

        #footer_btn{
          flex: 1;
          width: 100%;
          text-align: center;
          z-index: 99;
        }

        .btn{
          background: #FFFFFF;
          box-shadow: 0 2px 4px 0 rgba(0,0,0,0.10);
          border-radius: 1rem;
          margin: 0 auto;
          width: 70%;
          padding: 0.25rem;

        }

        .swiper-container {
            display: flex;
            flex-direction: column;
            height: 100%;
            justify-content: center;
            align-items: center;
        }

        .swiper-wrapper {
            align-items: center;
        }

        .swiper-slide {
            background: #c2c2c2;
            border-radius: 0.5rem;
            height: 10rem;
            left: -20px;
            opacity: 0.7;
            overflow: hidden;
        }

        .swiper-slide img {
            width: 100%;
            height: 100%
        }

        .swiper-slide-active {
            background: #fff;
            opacity: 1;
            height: 12rem !important;
            width: 8rem !important;
        }
    </style>
</head>

<body>
    <div id="app">
        <div id="header">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <template v-for="item in data">
                      <div class="swiper-slide">
                        <img :src="item.icon" alt="">
                      </div>
                    </template>
                </div>

            </div>
        </div>
        <div id="footer_btn">
            <div onclick="btn_confirm()" class="btn">
              确认选中
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/util.js"></script>
<script type="text/javascript" src="../script/swiper.min.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript">
    var app = '';
    var index = 0;
    var data = [];
    var level_id1,from1,major_type1,host1,text;
    apiready = function() {
      app = new Vue({
          el: '#app',
          data: {
              data: []
          },
            updated:function(){
              this.$nextTick(function () {
                var swiper = new Swiper('.swiper-container', {
                    freeMode: false,
                    slidesPerView: 3,
                    spaceBetween: 20,
                    loop: true,
                    centeredSlides: true,
                    pagination: {
                        el: '.swiper-pagination',
                    },
                    on:{
                      slideChange: function(){
                        console.log(this.realIndex);
                        level_id1 = this.realIndex;
                        from1 = data[this.realIndex]['app'];
                        console.log(from1);
                        major_type1 = data[this.realIndex]['major_type'];
                        console.log(major_type1);

                        text = data[this.realIndex]['text'];

                        host1 = data[this.realIndex]['host'];
                      }
                    }
                });
              })
            }
      });
      getLevel();
    };



    //获取等级数据
    function getLevel() {
        api.ajax({
            url: 'https://api.laoyaojing.net/Public/getMajorList',
            method: 'get',
        }, function(ret, err) {
            if (ret) {
                console.log(JSON.stringify(ret));
                if (ret.code == 200) {
                  data = ret.result.apps;
                  app.data = ret.result.apps;
                }
            } else {
                alert(JSON.stringify(err));
            }
        });

    }

    //确认选择
    function btn_confirm()
    {
        console.log(123);
        console.log(from1);
        console.log(major_type1);
        $api.setStorage('level_id', level_id1);
        $api.setStorage('from', from1);
        $api.setStorage('major_type', major_type1);
        $api.setStorage('host', host1);
        $api.setStorage('text', text);

        getMiniId();

        api.openWin({
            name: 'root',
            reload: true,
            url: '../index.html',
            slidBackEnabled:false
        });
    }
</script>

</html>
